{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "7a5a4ec7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "664e4377",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             counts\n",
      "dishes_name        \n",
      "38度剑南春         24.0\n",
      "42度海之蓝         25.0\n",
      "50度古井贡酒        21.0\n",
      "52度泸州老窖        22.0\n",
      "53度茅台          39.0\n",
      "...             ...\n",
      "麻辣小龙虾         189.5\n",
      "黄尾袋鼠西拉子红葡萄酒    53.0\n",
      "黄油曲奇饼干         28.0\n",
      "黄花菜炒木耳         62.0\n",
      "黑米恋上葡萄         58.0\n",
      "\n",
      "[145 rows x 1 columns]\n",
      "=================\n",
      "最大值: 189.5\n",
      "最大值: 3.0\n"
     ]
    }
   ],
   "source": [
    "data = pd.read_csv('sale.csv', encoding='GB2312', encoding_errors='ignore')\n",
    "data = data.groupby('dishes_name').sum()\n",
    "\n",
    "q1 = data['counts'].quantile(0.25)\n",
    "q3 = data['counts'].quantile(0.75)\n",
    "iqr = q3 - q1\n",
    "# 下界\n",
    "outliers_ll = q1 - 1.5*iqr\n",
    "# 上界\n",
    "outliers_ul = q3 + 1.5*iqr\n",
    "\n",
    "data[data['counts'] < outliers_ll] = outliers_ll\n",
    "data[data['counts'] > outliers_ul] = outliers_ul\n",
    "\n",
    "print(data)\n",
    "print('=================')\n",
    "print('最大值: ' + str(data['counts'].max()))\n",
    "print('最大值: ' + str(data['counts'].min()))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac7fb557",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
